#define _GNU_SOURCE
// #define __USE_GNU 1 
#include <sched.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
// int lock_thread = 0;
// int lock_main = 0;
// void spin_lock(int * lock){
	// while(__sync_lock_test_and_set(lock,1)){
		// usleep(5000);
	// };
// }
// void spin_release(int * lock){
// 	__sync_lock_release(lock);
// }
int shared = 0;
int thread(void *args)
{
	while (1)
	{
		// spin_lock(&lock_thread);
		shared++;
		printf("\033[32m[ thread ] \033[0mshared is %d\n", shared);
		// spin_release(&lock_main);
	}
	return 0;
}
int main()
{
	// spin_lock(&lock_main);
	void *heap = malloc(1024 * 1024);
	clone(thread, heap + 1024 * 1024, CLONE_VM | CLONE_FILES | CLONE_FS | CLONE_SIGHAND, NULL);
	while (1)
	{
		// spin_lock(&lock_main);
		printf("\033[32m[  main  ] \033[0mshared is %d\n", shared);
		// spin_release(&lock_thread);
		usleep(1000000);
	}

	return 0;
}
